home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Windows Selection / Windows Selection 1.iso / Graphics / Formula Graphics Multimedia System / CALC.SXT < prev    next >
Encoding:
Text File  |  1996-06-30  |  2.6 KB  |  95 lines

  1. init_calculator:
  2.     debug "initializing calculator ..."
  3.     rect = get element "number keys"
  4.     xpos = rect.xpos
  5.     ypos = rect.ypos
  6.     xlen = rect.xlen
  7.     ylen = rect.ylen
  8.     ulen = (xlen - 4) / 3
  9.     vlen = (ylen - 4) / 4
  10.     buttons = new byte[12][10]
  11.     $buttons[0] = "1";"2";"3";"4";"5";"6";"7";"8";"9";"0";"+/-";"."
  12.     for n = 0 to 3
  13.         for m = 0 to 2
  14.             btn = new element "Text Button"
  15.             element btn position xpos+ulen*m+2, ypos+vlen*n+2 size ulen, vlen
  16.             element btn set "text" color 250,250,250
  17.             element btn set "face" color 100,100,140
  18.             $btn.text = $buttons[n * 3 + m]
  19.             $btn.font_face = "Arial"
  20.             btn.font_weight = 700
  21.             btn.font_height = -22
  22.             $btn.action = "script calculator call number_button: \"", $btn.text, "\""
  23.             display element btn
  24.  
  25.     rect = get element "operator keys"
  26.     xpos = rect.xpos
  27.     ypos = rect.ypos
  28.     xlen = rect.xlen
  29.     ylen = rect.ylen
  30.     ulen = (xlen - 4) / 2
  31.     vlen = (ylen - 4) / 4
  32.     buttons = new byte[12][10]
  33.     $buttons[0] = "+";"-";"╫";"≈";"C";"M";"Next";"="
  34.     for n = 0 to 1
  35.         for m = 0 to 3
  36.             btn = new element "Text Button"
  37.             element btn position xpos+n*ulen+2, ypos+vlen*m+2 size ulen, vlen
  38.             element btn set "text" color 250,250,250
  39.             element btn set "face" color 100,100,140
  40.             $btn.text = $buttons[n * 4 + m]
  41.             $btn.font_face = "Arial"
  42.             btn.font_weight = 700
  43.             btn.font_height = -22
  44.             $btn.action = "script calculator call operator_button: \"", $btn.text, "\""
  45.             display element btn
  46.     $operator = ""
  47.     old_num = 0
  48.     new_flag = TRUE
  49.  
  50. number_button: key
  51.     debug $key
  52.     $num = getedit "lcd display"
  53.     if (key[0] >= '0' && key[0] <= '9') || key[0] == '.'
  54.         if new_flag
  55.             editbox "lcd display" = $key
  56.             new_flag = FALSE
  57.             return
  58.         for n = 0 to strlen $num - 1
  59.             if num[n] == 'e'
  60.                 $num = $num strcnt n, $key, $num stroff n
  61.                 editbox "lcd display" = $num
  62.                 return
  63.         $num = $num, $key
  64.     else if $key == "+/-" then $num = -1 * strval $num
  65.     editbox "lcd display" = $num
  66.  
  67. operator_button: key
  68.     debug $key
  69.     $num = getedit "lcd display"
  70.     if $key == "C"
  71.         old_num = 0
  72.         $operator = ""
  73.         editbox "lcd display" = ""
  74.         return
  75.  
  76.     if $key == "Next"
  77.         element action "next"
  78.         return
  79.  
  80.     debug old_num," ",$operator," ",strval $num
  81.     if $operator == "+" then new_num = old_num + strval $num
  82.     else if $operator == "-" then new_num = old_num - strval $num
  83.     else if $operator == "╫" then new_num = old_num * strval $num
  84.     else if $operator == "≈"
  85.         if strval $num == 0 then new_num = 0
  86.         else 
  87.             new_num = old_num / strval $num
  88.     else new_num = strval $num
  89.     old_num = new_num
  90.  
  91.     editbox "lcd display" = new_num
  92.     $operator = $key
  93.     new_flag = TRUE
  94.  
  95.